package com.spic.business.plan.team.service.impl;

import java.util.List;
import com.spic.common.core.utils.DateUtils;
import com.spic.common.core.utils.SecurityUtils;
import com.spic.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spic.business.plan.team.mapper.PlanPostMapper;
import com.spic.business.plan.team.domain.PlanPost;
import com.spic.business.plan.team.service.IPlanPostService;

/**
 * 应急岗位Service业务层处理
 * 
 * @author spic
 * @date 2021-11-10
 */
@Service
public class PlanPostServiceImpl implements IPlanPostService 
{
    @Autowired
    private PlanPostMapper planPostMapper;

    /**
     * 查询应急岗位
     * 
     * @param id 应急岗位主键
     * @return 应急岗位
     */
    @Override
    public PlanPost selectPlanPostById(Long id)
    {
        return planPostMapper.selectPlanPostById(id);
    }

    /**
     * 查询应急岗位列表
     * 
     * @param planPost 应急岗位
     * @return 应急岗位
     */
    @Override
    public List<PlanPost> selectPlanPostList(PlanPost planPost)
    {
        return planPostMapper.selectPlanPostList(planPost);
    }

    /**
     * 新增应急岗位
     * 
     * @param planPost 应急岗位
     * @return 结果
     */
    @Override
    public int insertPlanPost(PlanPost planPost)
    {
        planPost.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        planPost.setCreateTime(DateUtils.getNowDate());
        return planPostMapper.insertPlanPost(planPost);
    }

    /**
     * 修改应急岗位
     * 
     * @param planPost 应急岗位
     * @return 结果
     */
    @Override
    public int updatePlanPost(PlanPost planPost)
    {
        return planPostMapper.updatePlanPost(planPost);
    }

    /**
     * 批量删除应急岗位
     * 
     * @param ids 需要删除的应急岗位主键
     * @return 结果
     */
    @Override
    public int deletePlanPostByIds(Long[] ids)
    {
        return planPostMapper.deletePlanPostByIds(ids);
    }

    /**
     * 删除应急岗位信息
     * 
     * @param id 应急岗位主键
     * @return 结果
     */
    @Override
    public int deletePlanPostById(Long id)
    {
        return planPostMapper.deletePlanPostById(id);
    }
    /**
     * 校验岗位名称是否重复
     *
     * @param planPost 应急队伍分组
     * @return 结果 0 不重复  1重复  2修改不重复 新增重复
     */
    public int checkName(PlanPost planPost){
        if(StringUtils.isNotEmpty(planPost.getPostName())) {
            if (planPostMapper.selectByName(planPost.getPostName())!=null){
                if (!planPostMapper.selectByName(planPost.getPostName()).getId().equals(planPost.getId())){
                    return 1;
                }else{
                    return 2;
                }
            }else{
                return 0;
            }
        }else{
            return 0;
        }
    }
}
